package code.structure.module.storage.manager
{
	import code.structure.manager.language.LanguageManager;
	import code.structure.module.configs.ConfigModel;
	import code.structure.module.storage.StorageModel;
	import code.structure.module.storage.data.StorageData;
	import code.untils.CommandNameConst;
	
	import com.patience.mvc.context.Command;
	
	import flash.utils.Dictionary;
	/**
	 *动物仓库管理器 
	 * @author liangqian
	 * 
	 */	
	public class AnimalManager
	{
		private var _dic:Dictionary = new Dictionary();
		private var _configModel:ConfigModel;
		private var _command:Command = new Command('');
		private var _storageModel:StorageModel;
		public function AnimalManager(configModel:ConfigModel,storageModel:StorageModel)
		{
			_configModel = configModel;
			_storageModel = storageModel;
		}
		
		public function parser(d:Object):void
		{
			var hD:StorageData = new StorageData();
			hD.id = d.id;
			hD.num = d.num;
			hD.configData = _configModel.analysisItem.getItemConfigDataById(hD.id);
			_dic[hD.id] = hD;
		}
		
		public function addStorageData(id:int,num:int,isDispatch:Boolean = false):void
		{
			var hD:StorageData = _dic[id];
			if(!hD)
			{
				hD = new StorageData();
				hD.id = id;
				hD.configData = _configModel.analysisItem.getItemConfigDataById(id);
			}
			if (hD.maxLimit != 0 && (hD.num + num > hD.maxLimit))
			{
				if(isDispatch)
				{
				//_command.cmdName = CommandNameConst.COMMAND_WARN_MSG_EFFECT;
				//_command.target = [LanguageManager.getLanguageInfo('WARN_6')];
				//_command.data = WarnMsgEffectController.STORAGE_LIMIT;
				//_storageModel.dispatch(_command);
				}
				return;
			}
			hD.num += num;
		}
	}
}